package vg.services.data_base_manager.interfaces;

import java.util.List;
import java.util.Set;

import vg.services.data_base_manager.data.graph.Attribute;
import vg.services.data_base_manager.data.graph.Edge;
import vg.services.data_base_manager.data.graph.Graph;
import vg.services.data_base_manager.data.graph.Vertex;
import vg.services.data_base_manager.data.header.AttributeHeader;
import vg.services.data_base_manager.data.header.GraphHeader;
import vg.services.data_base_manager.data.header.GraphModelHeader;
import vg.services.data_base_manager.data.header.VertexHeader;
import vg.services.data_base_manager.data.skeleton.GraphTreeElement;

/**
 * Interface for graph data base.
 *
 * @author Timur Zolotuhin (e-mail: tzolotuhin@gmail.com)
 */
public interface IGraphDataBase {
	/**
	 * Creates header for the graph model and returns the unique id.
     *
	 * @param name - name of the graph.
	 */
	public int createGraphModelHeader(String name);

	/**
	 * Creates header for the graph and returns the unique id.
     *
	 * @param graphModelId - id of graph model, which will contains the graph. 
	 * @param directed - true - if the graph is directed, otherwise false.
     * @param root - true - if the graph is root, otherwise false.
	 */
	public int createGraphHeader(int graphModelId, boolean directed, boolean root);
	
	/**
	 * Creates header for the vertex and returns the unique id.
     *
	 * @param graphId - id of graph, which will contains the vertex.
	 * @param innerGraphId - link to inner graph, which is in this vertex.
	 */
	public int createVertexHeader(int graphId, int innerGraphId);

	/**
	 * Creates header for the edge and returns the unique id.
     *
	 * @param graphId - id of graph, which will contain the edge.
	 * @param sourceVertexId - id of source vertex.
	 * @param targetVertexId - id of target vertex.
	 */
	public int createEdgeHeader(int graphId, int sourceVertexId, int targetVertexId);
	
	/**
	 * Creates header for the attribute and returns the unique id.
     *
	 * @param edgeId - id of edge, which will contain the attribute.
     * @param name - attribute name.
     * @param strValue - string attribute value.
     * @param valueType - type of value. See AttributeHeader types: STRING_ATTRIBUTE_TYPE, INTEGER_ATTRIBUTE_TYPE, etc.
	 */
	public int createEdgeAttributeHeader(int edgeId, String name, String strValue, int valueType);
	
	/**
	 * Creates header for the attribute and returns the unique id.
     *
	 * @param vertexId - id of vertex, which will contain the attribute.
     * @param name - attribute name.
     * @param strValue - string attribute value.
     * @param valueType - type of value. See AttributeHeader types: STRING_ATTRIBUTE_TYPE, INTEGER_ATTRIBUTE_TYPE, etc.
     */
	public int createVertexAttributeHeader(int vertexId, String name, String strValue, int valueType);

    /**
     * Creates header for the attribute and returns the unique id.
     *
     * @param graphId - id of graph, which will contain the attribute.
     * @param name - attribute name.
     * @param strValue - string attribute value.
     * @param valueType - type of value. See AttributeHeader types: STRING_ATTRIBUTE_TYPE, INTEGER_ATTRIBUTE_TYPE, etc.
     */
    public int createGraphAttributeHeader(int graphId, String name, String strValue, int valueType);

    /**
     * Modifies existing graph model header.
     */
    public boolean modifyGraphModelHeader(GraphModelHeader newGraphModelHeader);

    /**
     * Modifies existing vertex header.
     */
    public boolean modifyVertexHeader(VertexHeader newVertexHeader);

    /**
     * Modifies existing attribute header.
     */
    public boolean modifyAttributeHeader(AttributeHeader newAttributeHeader);

    /**
	 * Builds subgraph from input vertex indices and returns it.
	 */
	public Graph getSubGraph(List<Integer> vertexIds);
	
	/**
	 * This method returns graph by id.
	 */
	public Graph getGraph(int graphId);
	
	/**
	 * Returns some root graph by graph model id.
	 */
	public Graph getSomeRootGraphByGraphModelId(int graphModelId);

    /**
     * Returns collection, which contains all root graph id fir the graph model.
     */
    public Set<Integer> getAllRootGraphIds(int graphModelId);

    /**
	 * Returns edge by id.
	 */
	public Edge getEdge(int edgeId);
	
	/**
	 * Returns vertex by id.
	 */
	public Vertex getVertex(int vertexId);
	
	/**
	 * Returns attribute by id.
	 */
	public Attribute getAttribute(int attrId);
	
	/**
	 * Returns header by id.
	 */
	public GraphModelHeader getGraphModelHeader(int graphModelId);

    /**
     * Returns header by id.
     */
    public GraphHeader getGraphHeader(int graphId);

    /**
     * Returns header by id.
     */
    public VertexHeader getVertexHeader(int vertexId);

    /**
     * Returns header by id.
     */
    public AttributeHeader getAttributeHeader(int attributeId);

    /**
     * Returns all graph model indices.
     */
    public Set<Integer> getAllGraphModelIds();

	/**
	 * Closes data base.
	 */
	public void close();
	
	/**
	 * Executes SQL request.
	 */
	public List<List<Object>> executeSQLRequest(String request);
	
	/**
	 * Returns tree for graph model.
	 */
	public GraphTreeElement getGraphModelTree(int graphModelId);

//==============================================================================
//--------------OTHER METHODS---------------------------------------------------
    /**
     * Returns all vertex indexes for the graph model.
     */
    public Set<Integer> getAllVertexIds4GraphModel(int graphModelId);

    /**
     * Returns all vertex indices in the graph and all vertex indices
     * in inner graph (if vertex of the graph contains link to it) and etc.
     */
    public Set<Integer> getAllVertexIds4Graph(Graph graph);

    /**
	 * Generates title for graph.
	 */
	public String generateTitle4Graph(Graph graph);
}
